terraform {
  backend "s3" {
    bucket = {{ .Values.Bucket | quote }}
    key = "{{ .Values.__CLUSTER__ }}/{{ .Values.Prefix }}/terraform.tfstate"
    region = {{ .Values.Region | quote }}
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.63.0"
    }
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = "~> 2.23.0"
    }
  }
}

provider "aws" {
  region = {{ .Values.Region | quote }}
}

data "aws_eks_cluster" "cluster" {
  name = {{ .Values.Cluster }}
}

data "aws_eks_cluster_auth" "cluster" {
  name = {{ .Values.Cluster }}
}

provider "kubernetes" {
  host                   = data.aws_eks_cluster.cluster.endpoint
  cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority.0.data)
  token                  = data.aws_eks_cluster_auth.cluster.token
}